import { FC, ReactNode } from 'react';
import { Form as AntdForm, Spin } from 'antd';
import type { FormProps as AntdFormProps } from 'antd/lib/form';
import classNames from 'classnames';

export const useForm = AntdForm.useForm;
export const useFormInstance = AntdForm.useFormInstance;
export const useWatch = AntdForm.useWatch;
export const Item = AntdForm.Item;
export const List = AntdForm.List;
export const ErrorList = AntdForm.ErrorList;
/** @deprecated Only for warning usage. Do not use. */
export const create = AntdForm.create;

export type FormProps = AntdFormProps & {
  /**
   * 加载状态
   * @default false
   */
  loading?: boolean;

  children: ReactNode;
};

const Form: FC<FormProps> = ({ className, loading = false, children, ...rest }) => {
  return (
    <Spin spinning={loading}>
      <AntdForm className={classNames(className)} {...rest}>
        {children}
      </AntdForm>
    </Spin>
  );
};

// 设置默认属性
Form.defaultProps = {
  // ...AntdForm.defaultProps,
  size: 'small',
  labelCol: { span: 8 },
  wrapperCol: { span: 16 },
  labelWrap: true
};

export default Form;
